package com.yugao.fintech.draper.core.support;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringBootVersion;
import org.springframework.core.env.Environment;

import java.util.concurrent.TimeUnit;

@Slf4j
public class CustomizerBanner implements ApplicationRunner {

    private final String doc = "http://draper-gateway:9999";

    private final String bootVersion = SpringBootVersion.getVersion();

    private final String name;

    private final String osName;

    private final String osArch;

    private final String osVersion;

    private final String javaVendor;

    private final String javaVersion;

    public CustomizerBanner(Environment environment) {
        name = environment.getProperty("spring.application.name");
        osName = environment.getProperty("os.name");
        osArch = environment.getProperty("os.arch");
        osVersion = environment.getProperty("os.version");
        javaVendor = environment.getProperty("java.vendor");
        javaVersion = environment.getProperty("java.version");
    }

    @Override
    public void run(ApplicationArguments args) {
        ThreadUtil.execute(() -> {
            ThreadUtil.sleep(3, TimeUnit.SECONDS);
            log.info("操作系统：{},{},{}", osName, osArch, osVersion);
            log.info("Java环境：{},{}", javaVendor, javaVersion);
            log.info("SpringBoot版本：{}", bootVersion);
            log.info("项目启动成功！服务:{} ", name);
            log.info("项目文档相关:{}", doc);
        });
    }
}